<?php
session_start();
include("database_connect.php");

class Model 
{
	public function login($email,$password)
	{
		// Login procedure
		 if (empty($email)) 
		 {
        	$error = '* You forgot to enter your Email';
    	 }
		 elseif(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) 
			{
            	$error = '* Your email address is invalid';	
        	}
		elseif(empty($password)) 
		{
        	$error = '* Please Enter Your Password ';
    	} 
		elseif(empty($error))
    	{ 
	        $query_check_credentials = "select * from user where email='".$email."' and pass='".$password."' AND userkey IS NULL";
        	$result_check_credentials = mysql_query($query_check_credentials);
        	if(!$result_check_credentials)
			{
            	echo 'Query Failed ';
        	}
        	if (@mysql_num_rows($result_check_credentials) == 1)
        	{
            	$credentials = mysql_fetch_array($result_check_credentials);
				
				$_SESSION['user_id'] = $credentials['user_id'];
				$_SESSION['username'] = $credentials['username'];
				$_SESSION['fullname'] = $credentials['fullname'];
				$_SESSION['dob'] = $credentials['dob'];
				$_SESSION['gender'] = $credentials['gender'];
				$_SESSION['city'] = $credentials['city'];
				
				/*if($credentials['dob'] != "")
				{
					$_SESSION['dob'] = $credentials['dob'];
				}
				if($credentials['gender'] != "")
				{
					$_SESSION['gender'] = $credentials['gender'];
				}
				if($credentials['city'] != "")
				{
					$_SESSION['city'] = $credentials['city'];
				}*/
				
				?>
            	<script>window.location = "view/mandatory.php";</script>
				<?php

				return;
				//header("Location: view/dashboard.php");
				
        	}
			else
        	{
				$error = "* Password for this user does not match"; 
			}
        }
    	else 
		{
			$error= "* Password for this user does not match";
	    }
		print_r($error);
	} 
	

	public function register($name,$email,$password)
	{
		if(empty($name) || $name == "Name") 
		{
			$error =  '* Please Enter a name ';
    	} 
    	elseif(empty($email) || $email == "E-mail")
		{
			$error = '* Please Enter your Email ';
    	}
		elseif (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) 
		{
            $error = '* Your Email Address is invalid  ';
        }
        elseif(empty($password) || $password == "Password") 
		{
        	$error = '* Please Enter Your Password ';
    	}
		elseif(empty($error)) //send to Database if there's no error '
    	{ // If everything's OK...
        	// Make sure the email address is available:
        	$query_verify_email = "SELECT * FROM user  WHERE email ='$email'";
        	$result_verify_email = mysql_query($query_verify_email);
        	if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false)
            	echo ' Database Error Occured ';
        }
        if(mysql_num_rows($result_verify_email) == 0) 
		{ 		
			$name = mysql_real_escape_string($name);
			$email = mysql_real_escape_string($email);
			$password = mysql_real_escape_string($password);

			// IF no previous user is using this email .
            // Create a unique  activation code:
            //$activation = md5(uniqid(rand(), true));
            $query_insert_user = "INSERT INTO `user`(`fullname`, `gender`, `dob`, `relationship`, `city`, `citizenship`, `about`, `workfield`, `interest`, `phone`, `mobile`, `email`, `pass`, `fax`, `school`, `college`, `pgcollege`, `other`, `username`, `profilepic`) VALUES ('".$name."','','','','','','','','','','','".$email."','".$password."','','','','','','','')";
            $result_insert_user = mysql_query($query_insert_user);
            if (!$result_insert_user) 
			{
                echo 'Query Failed ';
            }
            if (mysql_affected_rows() == 1)
			{
                //$message = " To activate your account, please click on this link:\n\n";
                //$message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
				$message = "Dear Bhavika Thakkar\nThank you for registering with ve.com. Your journey to success begins now!\n\nPlease find below your account details:\nUsername: ".$email."\nPassword: ".$password." \n DO NOT REPLY TO THIS MAIL \n You received this email as a member of VaultEmpire.com ";
                mail($email, 'Registration Confirmation', $message, 'From: bhavikat6@gmail.com');
				$this->login($email,$password);
                // Finish the page:
			}
			else 
			{ // If it did not run OK.
                $error = '* Oops something went wrong.';
            }
		} 
		else 
		{	 // The email address is not available.
           	$error = '* Email Id already registered';
		}
		
		}
		echo $error;
	}
	
	
	public function submitMandatoryData($city,$dob,$gender)
	{
		
		//$update = mysql_query("UPDATE `user` SET city = '".$city."' ,`dob` ='".$dob."' ,`gender`='".$gender."' WHERE `user_id`='".$_SESSION['user_id']."'");
		
		//$replyQuery = mysql_query("INSERT INTO `test`(`test`, `test1`) VALUES ('".$city."','".$dob."')");
		
		
		 if (empty($city) || $city == "city") 
		 {
        	$error = '* You forgot to enter City';
    	 }
		elseif(empty($dob) || $dob == "dob") 
		{
        	$error = '* Please Enter Your Date of birth ';
    	}
		elseif(empty($error))
    	{
			$city = mysql_real_escape_string($city);
			$dob = mysql_real_escape_string($dob);
			$gender = mysql_real_escape_string($gender); 

	        $query_check_credentials = "update user set city='".$city."',dob='".$dob."',gender='".$gender."' where user_id='".$_SESSION['user_id']."'";
        	$result_check_credentials = mysql_query($query_check_credentials);
			
        	if(!$result_check_credentials)
			{
            	echo 'Query Failed ';
        	}
        	else
			{
				$credentials = mysql_query("select * from user where user_id='".$_SESSION['user_id']."'");
				$result = mysql_fetch_array($credentials);
				$_SESSION['city'] = $result['city'];
				$_SESSION['dob'] = $result['dob'];
				$_SESSION['gender'] = $result['gender'];
				?>
           	<script>
			window.location = "view/dashboard.php";</script>
			<?php
				return;
				//header("Location: view/dashboard.php");
        	}
        }
    	else 
		{
			$error= "* Oops something went wrong";
	    }
		print_r($error);
	}
	
	
	
	public function statusUpdate($status,$privacy)
	{
		 if (empty($status)) 
		 {
        	$error = '* Please enter some status';
    	 }
		elseif(empty($error))
    	{ 
		if($privacy == 'public')
		{
			$pr = 2;
		}
		elseif($privacy == "private")
		{
			$pr = 0;
		}
		elseif($privacy == 'friends')
		{
			$pr = 1;
		}
		
		$timeAr = getdate();
		$status = mysql_real_escape_string($status);

	        $query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','status','".$status."','','','".$pr."','','','','".$timeAr[0]."')";
        	$result_check_credentials = mysql_query($query_check_credentials);			
			$error = "<span style='color:green'>Status updated successfully</span>";
        }
    	else 
		{
			$error= "* Oops something went wrong";
	    }
		print_r($error);
	} 
	
	function ago($original) 
	{
		// array of time period chunks
		$chunks = array(
			array(60 * 60 * 24 * 365 , 'year'),
			array(60 * 60 * 24 * 30 , 'month'),
			array(60 * 60 * 24 * 7, 'week'),
			array(60 * 60 * 24 , 'day'),
			array(60 * 60 , 'hour'),
			array(60 , 'minute'),
		);
	   
		$today = time(); /* Current unix time  */
		$since = $today - $original;
	   
		// $j saves performing the count function each time around the loop
		for ($i = 0, $j = count($chunks); $i < $j; $i++) {
		   
			$seconds = $chunks[$i][0];
			$name = $chunks[$i][1];
		   
			// finding the biggest chunk (if the chunk fits, break)
			if (($count = floor($since / $seconds)) != 0) {
				// DEBUG print "<!-- It's $name -->\n";
				break;
			}
		}
	   
		$print = ($count == 1) ? '1 '.$name : "$count {$name}s";
	   
		if ($i + 1 < $j) {
			// now getting the second item
			$seconds2 = $chunks[$i + 1][0];
			$name2 = $chunks[$i + 1][1];
		   
			// add second item if it's greater than 0
			if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
				$print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
			}
		}
		return $print;
	}
	
	function getUserStatus()
	{
		$statusQuery = mysql_query("select * from document where user_id='".$_SESSION['user_id']."' ORDER BY `update_time` DESC");
		$i=0;
		$userStatus[] = "";
		while($row = mysql_fetch_array($statusQuery))
		{
			$userStatus[$i]['id'] = $row['id'];
			$userStatus[$i]['type'] = $row['type'];
			$userStatus[$i]['comment'] = $row['comment'];
			$userStatus[$i]['url'] = $row['url'];
			$userStatus[$i]['category']= $row['category'];
			$userStatus[$i]['privacy'] = $row['privacy'];
			$userStatus[$i]['thumbnail'] = $row['thumbnail'];
			$userStatus[$i]['place'] = $row['place'];
			$userStatus[$i]['date'] = $row['date'];
			$userStatus[$i]['update_time'] = $this->ago($row['update_time']);
			$userStatus[$i]['like'] = $row['like'];
			$userStatus[$i]['dislike'] = $row['dislike'];
			$userStatus[$i]['comments'] = $row['comments'];
			$userStatus[$i]['user_id'] = $row['user_id'];
			$likesArray = explode(",",$row['likes']);
			if(in_array($_SESSION['user_id'] , $likesArray))
			{
				$userStatus[$i]['likes'] = true;
			}
			else
			{
				$userStatus[$i]['likes'] = false;
			}
			$dislikesArray = explode(",",$row['dislikes']);
			if(in_array($_SESSION['user_id'] , $dislikesArray))
			{
				$userStatus[$i]['dislikes'] = true;
			}
			else
			{
				$userStatus[$i]['dislikes'] = false;
			}
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $userStatus;
		}	
	}
	
	function logout()
	{
		session_destroy();
	}
	
	function musicFileUpload($comment,$title,$ext,$privacy,$category)
	{
		$comment = urldecode($comment);
		$title = urldecode($title);
		
		if(!is_dir("tmp/".$_SESSION['user_id']))
  			mkdir("tmp/".$_SESSION['user_id'],0777);
		if(!is_dir("tmp/".$_SESSION['user_id']."/music"))
  			mkdir("tmp/".$_SESSION['user_id']."/music",0777);
			
		$file_id='file';
		$status='';
		$folderId = '1';
		$inserId = 0;
		$filename=$_FILES[$file_id]['name'];
		$tmpfile=$_FILES[$file_id]['tmp_name'];
		$timeAr = getdate();
		if(!$_FILES[$file_id]['name']) {
			$error = "<span style='color:red'>No file specified</span>";
  		}
		elseif($ext == "au" || $ext == "snd" || $ext == "mid" || $ext == "rmi" || $ext== "mp3" || $ext == "aif" || $ext == "aifc" || $ext == "aiff" || $ext== "m3u" || $ext== "ra" || $ext== "ram" || $ext== "wav")
		{
			if(move_uploaded_file($tmpfile, "tmp/".$_SESSION['user_id']."/music/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				if($privacy == 'public')
				{
					$pr = 2;
				}
				elseif($privacy == "private")
				{
					$pr = 0;
				}
				elseif($privacy == 'friends')
				{
					$pr = 1;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','music','".$comment."','".$filename."','".$category."','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				
				$album="INSERT INTO `album`(`album`,`user_id`) VALUES ('".$title."','".$_SESSION['user_id']."')";
				$error = "<span style='color:green'>File added successfully</span>";
			}
			else
			{
				$error = "<span style='color:red'>File upload failed</span>";
			}
		}
		else
		{
			$error = "<span style='color:red'>Invalid file type</span>";
		}
		return (mysql_real_escape_string($error));
		

	}
 
	function videoFileUpload($comment,$title,$ext,$privacy,$category)
	{
		if($title == "")
		{
			$title = $filename;
		}
		if($privacy == 'public')
		{
			$pr = 2;
		}
		elseif($privacy == "private")
		{
			$pr = 0;
		}
		elseif($privacy == 'friends')
		{
			$pr = 1;
		}
		$comment = urldecode($comment);
		$title = urldecode($title);
		if(!is_dir("temp/".$_SESSION['user_id']))
  			mkdir("temp/".$_SESSION['user_id'],0777);
		if(!is_dir("temp/".$_SESSION['user_id']."/video"))
  			mkdir("temp/".$_SESSION['user_id']."/video",0777);
			
		$file_id='videofile';
		$status='';
		$folderId = '1';
		$inserId = 0;
		$filename=$_FILES[$file_id]['name'];
		$tmpfile=$_FILES[$file_id]['tmp_name'];
		$timeAr = getdate();
		if(!$_FILES[$file_id]['name']) {
			$error = "<span style='color:red'>No file specified</span>";
  		}
		elseif($ext == "flv" || $ext == "mp4" || $ext == "m3u8" || $ext == "ts" || $ext== "3gp" || $ext == "mov" || $ext == "avi" || $ext == "wmv")
		{
			if(move_uploaded_file($tmpfile, "temp/".$_SESSION['user_id']."/video/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `place`, `date`) VALUES ('".$_SESSION['user_id']."','video','".$comment."','".$filename."','".$category."','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				$error = "<span style='color:green'>Video updated successfully</span>";
			}
			else
			{
				$error = "<span style='color:red'>Video updation failed</span>";
			}
		}
		else
		{
			$error = "<span style='color:red'>Invalid file type</span>";
		}
		
		return (mysql_real_escape_string($error));
		

	} 
	
	
	function imageFileUpload($comment,$title,$ext,$privacy,$category)
	{
		if($privacy == 'public')
		{
			$pr = 2;
		}
		elseif($privacy == "private")
		{
			$pr = 0;
		}
		elseif($privacy == 'friends')
		{
			$pr = 1;
		}
		$comment = urldecode($comment);
		$title = urldecode($title);
		if(!is_dir("tmp/".$_SESSION['user_id']))
  			mkdir("tmp/".$_SESSION['user_id'],0777);
		if(!is_dir("tmp/".$_SESSION['user_id']."/image"))
  			mkdir("tmp/".$_SESSION['user_id']."/image",0777);
			
		$file_id='imageFile';
		$status='';
		$folderId = '1';
		$inserId = 0;
		$filename=$_FILES[$file_id]['name'];
		$tmpfile=$_FILES[$file_id]['tmp_name'];
		$timeAr = getdate();
		if(!$_FILES[$file_id]['name']) {
			$error = "<span style='color:red'>No file specified</span>";
  		}
		elseif($ext == "3dm" || $ext == "3ds" || $ext == "max" || $ext == "obj" || $ext== "bmp" || $ext == "dds" || $ext == "dng" || $ext == "gif" || $ext == "jpg" || $ext == "png" || $ext == "psd" || $ext == "pspimage" || $ext == "tga"  || $ext == "thm" || $ext == "svg" || $ext == "tif" || $ext == "yuv" || $ext == "ai" || $ext == "eps" || $ext == "ps" )
		{
			if(move_uploaded_file($tmpfile, "tmp/".$_SESSION['user_id']."/image/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','image','".$comment."','".$filename."','".$category."','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				$error = "<span style='color:green'>Status updated successfully</span>";
			}
			else
			{
				$error = "<span style='color:red'>Status updation failed</span>";
			}
		}
		else
		{
			$error = "<span style='color:red'>Invalid file type</span>";
		}
		
		return (mysql_real_escape_string($error));
		

	} 


	function docFileUpload($comment,$title,$ext,$privacy,$category)
	{
		if($privacy == 'public')
		{
			$pr = 2;
		}
		elseif($privacy == "private")
		{
			$pr = 0;
		}
		elseif($privacy == 'friends')
		{
			$pr = 1;
		}
		$comment = urldecode($comment);
		$title = urldecode($title);
		if(!is_dir("tmp/".$_SESSION['user_id']))
  			mkdir("tmp/".$_SESSION['user_id'],0777);
		if(!is_dir("tmp/".$_SESSION['user_id']."/doc"))
  			mkdir("tmp/".$_SESSION['user_id']."/doc",0777);
			
		$file_id='docFile';
		$status='';
		$folderId = '1';
		$inserId = 0;
		$filename=$_FILES[$file_id]['name'];
		$tmpfile=$_FILES[$file_id]['tmp_name'];
		$timeAr = getdate();
		if(!$_FILES[$file_id]['name']) {
			$error[0] = mysql_real_escape_string("<span style='color:red'>No file specified</span>");
			$error[1]= "";
  		}
		elseif($ext == "app" || $ext == "bat" || $ext == "cgi" || $ext == "com" || $ext== "exe" || $ext == "gadget" || $ext == "jar" || $ext == "pif" || $ext == "vb" || $ext == "wsf")
		{
				$error[0] = mysql_real_escape_string("<span style='color:red'>Invalid file type</span>");
				$error[1] = "";
		}
		elseif($ext == "3dm" || $ext == "3ds" || $ext == "max" || $ext == "obj" || $ext== "bmp" || $ext == "dds" || $ext == "dng" || $ext == "gif" || $ext == "jpg" || $ext == "png" || $ext == "psd" || $ext == "pspimage" || $ext == "tga"  || $ext == "thm" || $ext == "svg" || $ext == "tif" || $ext == "yuv" || $ext == "ai" || $ext == "eps" || $ext == "ps" )
		{
			if(move_uploaded_file($tmpfile, "tmp/".$_SESSION['user_id']."/image/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','image','".$comment."','".$filename."','".$category."','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				$error[0] = mysql_real_escape_string("<span style='color:green'>Status updated successfully</span>");
				$error[1] = "image";
			}
			else
			{
				$error[0] = mysql_real_escape_string("<span style='color:red'>Status updation failed</span>");
				$error[1] = "doc";
			}
		}
		elseif($ext == "au" || $ext == "snd" || $ext == "mid" || $ext == "rmi" || $ext== "mp3" || $ext == "aif" || $ext == "aifc" || $ext == "aiff" || $ext== "m3u" || $ext== "ra" || $ext== "ram" || $ext== "wav")
		{
			if(move_uploaded_file($tmpfile, "tmp/".$_SESSION['user_id']."/music/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','music','".$comment."','".$filename."','','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				$error[0] = mysql_real_escape_string("<span style='color:green'>Status updated successfully</span>");
				$error[1] = "music";
			}
			else
			{
				$error[0] = mysql_real_escape_string("<span style='color:red'>Status updation failed</span>");
				$error[1] = "doc";
			}
		}
		elseif($ext == "flv" || $ext == "mp4" || $ext == "m3u8" || $ext == "ts" || $ext== "3gp" || $ext == "mov" || $ext == "avi" || $ext == "wmv")
		{
			if(move_uploaded_file($tmpfile, "tmp/".$_SESSION['user_id']."/video/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','video','".$comment."','".$filename."','','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				$error[0] = mysql_real_escape_string("<span style='color:green'>Status updated successfully</span>");
				$error[1] = "video";
			}
			else
			{
				$error[0] = mysql_real_escape_string("<span style='color:red'>Status updation failed</span>");
				$error[1] = "doc";
			}
		}
		else
		{
			if(move_uploaded_file($tmpfile, "tmp/".$_SESSION['user_id']."/doc/".$filename))
			{
				if($title == "")
				{
					$title = $filename;
				}
				$query_check_credentials = "INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`,`update_time`) VALUES ('".$_SESSION['user_id']."','doc','".$comment."','".$filename."','','".$pr."','','".$title."','','".$timeAr[0]."')";
				$result_check_credentials = mysql_query($query_check_credentials);
				$error[0] = mysql_real_escape_string("<span style='color:green'>Status updated successfully</span>");
				$error[1] = "doc";
			}
			else
			{
				$error[0] = mysql_real_escape_string("<span style='color:red'>Status updation failed</span>");
			}
		}
		
		return ($error);
		

	}
	
	function getStatusComment($statusId)
	{
		$statusQuery = mysql_query("SELECT comment.*,comment.id as comment_id,document.id,document.user_id,user.fullname FROM COMMENT,document,user WHERE onid = '".$statusId."' and comment.onid=document.id and comment_owner=user.`user_id` ORDER BY `created_time` ASC");
		$i=0;
		$userStatus[] = "";
		while($row = mysql_fetch_array($statusQuery))
		{
			$userStatus[$i]['id'] = $row['id'];
			$userStatus[$i]['text'] = $row['text'];
			$userStatus[$i]['comment_owner'] = $row['comment_owner'];
			$userStatus[$i]['onid'] = $row['onid'];
			$userStatus[$i]['created_time']= $this->ago($row['created_time']);
			$userStatus[$i]['type'] = $row['type'];
			$userStatus[$i]['user_id'] = $row['user_id'];
			//$userStatus[$i]['comment'] = $row['comment'];
			$userStatus[$i]['fullname'] = $row['fullname'];
			$userStatus[$i]['like'] = $row['like'];
			$userStatus[$i]['dislike'] = $row['dislike'];
			$userStatus[$i]['reply'] = $row['reply'];
			$userStatus[$i]['comment_id'] = $row['comment_id'];
			$likesArray = explode(",",$row['likes']);
			if(in_array($_SESSION['user_id'] , $likesArray))
			{
				$userStatus[$i]['likes'] = true;
			}
			else
			{
				$userStatus[$i]['likes'] = false;
			}
			$dislikesArray = explode(",",$row['dislikes']);
			if(in_array($_SESSION['user_id'] , $dislikesArray))
			{
				$userStatus[$i]['dislikes'] = true;
			}
			else
			{
				$userStatus[$i]['dislikes'] = false;
			}
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			foreach($userStatus as $row)
			{
			?>
			<div class="commenta">
                <div class="cmtboxsub"></div>
                <span class="cmntbox"><a href="" class="linkname"><?php echo $row['fullname']?></a> 
                <?php echo $row['text']; ?>
                </span>
                <div class="ldscbox">
                    <?php
						if($row['likes'] != 1)
						{
					?>
							 <?php   
							if($row['dislikes'] != 1)
							{ 
						?>
								<span id="commentlike<?php echo $row['comment_id']; ?>"><span class="spn"><a href="#a" onclick="likeComment(<?php echo $row['comment_id']; ?>)">Like-</a><span id="commentLike<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['like']; ?></span></span></span>
								<span id="commentdislike<?php echo $row['comment_id']; ?>"><span class="spn"><a href="#a" onclick="dislikeComment(<?php echo $row['comment_id']; ?>)">Dislike-</a><span id="commentDislike<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['dislike']; ?></span></span></span>
						<?php 
							}
							else
							{
								?>
								<span id="commentlike<?php echo $row['comment_id']; ?>"><span class="spn spancount">Like-<span id="commentLike<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['like']; ?></span></span></span>
								<span id="commentdislike<?php echo $row['comment_id']; ?>"><span class="spn"><img src="view/img/icons/Tick.png"><a href="#a" onclick="undislikeComment(<?php echo $row['comment_id']; ?>)">Dislike-</a><span id="commentDislike<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['dislike']; ?></span></span></span>
								<?php
							}
						}
						else
						{
							?>
							<span id="commentlike<?php echo $row['comment_id']; ?>"><span class="spn"><img src="view/img/icons/Tick.png"><a href="#a" onclick="unlikeComment(<?php echo $row['comment_id']; ?>)">Like-</a><span id="commentLike<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['like']; ?></span></span></span>
							<span id="commentdislike<?php echo $row['comment_id']; ?>"><span class="spn spancount">Dislike-<span id="commentDislike<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['dislike']; ?></span></span></span>
							<?php
						}
					?>
                    <spna class="spn"><a href="#a" onclick="$('#subcommentarea<?php echo $row['comment_id']; ?>').focus();showReply(<?php echo $row['comment_id']; ?>)">Reply-</a><span id="commentReply<?php echo $row['comment_id']; ?>" class="spancount"><?php echo $row['reply']; ?></span></spna>
                    <div class="cnamedetails">
                        <?php echo $row['created_time']; ?> ago <a href="#a"></a>
                    </div>
                </div>
            </div>
           
           
            <div id="subcommentBox<?php echo $row['comment_id']?>">
                
            </div>
            <div class="subcomment" id="subcomment<?php echo $row['comment_id']; ?>"> 
                <div class="commentare">
                    <div class="cmtboxsubre">
                    </div>
                    <textarea id="subcommentarea<?php echo $row['comment_id']; ?>" name="subcommentarea<?php echo $row['comment_id']; ?>" cols="20" rows="1" class="textareainneropp" placeholder="Write here !!!"></textarea>
                   	<script>
					$("#subcommentarea<?php echo $row['comment_id']; ?>").keyup(function(event){
						if(event.keyCode == 13){
							sendReply(<?php echo $row['comment_id']; ?>);
						}
					});
					</script>
                    
                </div>
            </div>
	<?php
			}
		}	
	} 
	
	
	
	function getCommentReply($commentId)
	{
		$statusQuery = mysql_query("SELECT comment.*,user.fullname FROM COMMENT,user WHERE onid = '".$commentId."'  and comment_owner=user.`user_id` ORDER BY `created_time` ASC");
		$i=0;
		$commentReply[] = "";
		while($row = mysql_fetch_array($statusQuery))
		{
			$commentReply[$i]['id'] = $row['id'];
			$commentReply[$i]['text'] = $row['text'];
			$commentReply[$i]['comment_owner'] = $row['comment_owner'];
			$commentReply[$i]['onid'] = $row['onid'];
			$commentReply[$i]['created_time']= $this->ago($row['created_time']);
			$commentReply[$i]['type'] = $row['type'];
			$commentReply[$i]['fullname'] = $row['fullname'];
			$commentReply[$i]['like'] = $row['like'];
			$commentReply[$i]['dislike'] = $row['dislike'];
			$commentReply[$i]['reply'] = $row['reply'];	
			$likesArray = explode(",",$row['likes']);
			if(in_array($_SESSION['user_id'] , $likesArray))
			{
				$commentReply[$i]['likes'] = true;
			}
			else
			{
				$commentReply[$i]['likes'] = false;
			}
			$dislikesArray = explode(",",$row['dislikes']);
			if(in_array($_SESSION['user_id'] , $dislikesArray))
			{
				$commentReply[$i]['dislikes'] = true;
			}
			else
			{
				$commentReply[$i]['dislikes'] = false;
			}
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			foreach($commentReply as $row)
			{
			?>
			<div class="commentare">
                <div class="cmtboxsubre"></div>
                <span class="cmntboxre"><a href="" class="linknamere"><?php echo $row['fullname']; ?></a> <?php echo $row['text']; ?>
                </span>
                <div class="ldscboxre">
                   <?php
						if($row['likes'] != 1)
						{
					?>
							 <?php   
							if($row['dislikes'] != 1)
							{ 
						?>
								<span id="replylike<?php echo $row['id']; ?>"><span class="spn"><a href="#a" onclick="likeReply(<?php echo $row['id']; ?>)">Like-</a><span id="replyLike<?php echo $row['id']; ?>" class="spancount"><?php echo $row['like']; ?></span></span></span>
								<span id="replydislike<?php echo $row['id']; ?>"><span class="spn"><a href="#a" onclick="dislikeReply(<?php echo $row['id']; ?>)">Dislike-</a><span id="replyDislike<?php echo $row['id']; ?>" class="spancount"><?php echo $row['dislike']; ?></span></span></span>
						<?php 
							}
							else
							{
								?>
								<span id="replylike<?php echo $row['id']; ?>"><span class="spn spancount">Like-<span id="replyLike<?php echo $row['id']; ?>" class="spancount"><?php echo $row['like']; ?></span>></span></span>
								<span id="replydislike<?php echo $row['id']; ?>"><span class="spn"><img src="view/img/icons/Tick.png"><a href="#a" onclick="undislikeReply(<?php echo $row['id']; ?>)">Dislike-</a><span id="replyDislike<?php echo $row['id']; ?>" class="spancount"><?php echo $row['dislike']; ?></span></span></span>
								<?php
							}
						}
						else
						{
							?>
							<span id="replylike<?php echo $row['id']; ?>"><span class="spn"><img src="view/img/icons/Tick.png"><a href="#a" onclick="unlikeReply(<?php echo $row['id']; ?>)">Like-</a><span id="replyLike<?php echo $row['id']; ?>" class="spancount"><?php echo $row['like']; ?></span></span></span>
							<span id="replydislike<?php echo $row['id']; ?>"><span class="spn spancount">Dislike-<?php echo $row['dislike']; ?></span></span>
							<?php
						}
					?>
                    <div class="cnamedetails">
                        <?php echo $row['created_time']; ?> ago <a href="">
                        </a>
                    </div>
                </div>
            </div>
	<?php
			}
		}	
	} 
	
	
	function sendCommentReply($commentId,$text)
	{
		$timeAr = getdate();

		$replyQuery = mysql_query("INSERT INTO `comment`(`text`, `comment_owner`, `onid`, `created_time`, `type`, `like`, `dislike`, `reply`) VALUES ('".$text."','".$_SESSION['user_id']."','".$commentId."','".$timeAr[0]."','reply','0','0','0')");
		$updateQuery = mysql_query("update comment set reply=reply+1 where id='".$commentId."'");
		?>
			<div class="commentare">
                <div class="cmtboxsubre"></div>
                <span class="cmntboxre"><a href="" class="linknamere"><?php echo $_SESSION['fullname']; ?></a> <?php echo $text; ?>
                </span>
                <div class="ldscboxre">
                    <spna class="spn"><a href="#a">Like</a></spna>
                    <spna class="spn"><a href="#a">Dislike</a></spna>
                    <div class="cnamedetails">
                        <?php echo $this->ago($timeAr[0]); ?> ago <a href="">
                        </a>
                    </div>
                </div>
            </div>
          <?php	
	}
	
	
	function sendComment($statusId,$text)
	{
		$timeAr = getdate();

		$replyQuery = mysql_query("INSERT INTO `comment`(`text`, `comment_owner`, `onid`, `created_time`, `type`, `like`, `dislike`, `reply`) VALUES ('".$text."','".$_SESSION['user_id']."','".$statusId."','".$timeAr[0]."','main','0','0','0')");
		$updateQuery = mysql_query("update document set comments=comments+1 where id='".$statusId."'");
		?>
			<div class="commenta">
                <div class="cmtboxsub"></div>
                <span class="cmntbox"><a href="" class="linkname"><?php echo $_SESSION['fullname']; ?></a> 
                <?php echo $text; ?>
                </span>
                <div class="ldscbox">
                    <spna class="spn"><a href="#a">Like-0</a></spna>
                    <spna class="spn"><a href="#a">Dislike--0</a></spna>
                    <spna class="spn"><a href="#a" onclick="$('#subcommentarea<?php echo mysql_insert_id(); ?>').focus();showReply(<?php echo mysql_insert_id(); ?>)">Reply-</a><span id="commentReply<?php echo mysql_insert_id(); ?>">0</span></spna>
                    <div class="cnamedetails">
                        0 minutes ago <a href="#a"></a>
                    </div>
                </div>
            </div>
           
           
            <div id="subcommentBox<?php echo mysql_insert_id(); ?>">
                
            </div>
            <div class="subcomment" id="subcomment<?php echo mysql_insert_id(); ?>"> 
                <div class="commentare">
                    <div class="cmtboxsubre">
                    </div>
                    <textarea id="subcommentarea<?php echo mysql_insert_id(); ?>" name="subcommentarea<?php echo mysql_insert_id(); ?>" cols="20" rows="1" class="textareainneropp" placeholder="Write here !!!"></textarea>
                   	<script>
					$("#subcommentarea<?php echo mysql_insert_id(); ?>").keyup(function(event){
						if(event.keyCode == 13){
							sendReply(<?php echo mysql_insert_id(); ?>);
						}
					});
					</script>
                </div>
            </div>
          <?php	
	}
	
	function likeStatus($statusId)
	{
		$updateQuery = mysql_query("update document set likes=concat(likes,',".$_SESSION['user_id']."') where id='".$statusId."'");
		$update = mysql_query("UPDATE `document` SET `like` = `like`+'1'  WHERE `document`.`id`=".$statusId);
	}
	function unlikeStatus($statusId)
	{
		$selectQuery = mysql_fetch_array(mysql_query("select likes from document where id='".$statusId."'"));
		$selecQueryElem = explode(",",$selectQuery['likes']);
		print_r($selecQueryElem);
		if(($key = array_search($_SESSION['user_id'], $selecQueryElem)) !== false) {
    		unset($selecQueryElem[$key]);
		}
		$selectQueryElemNew = implode(",",$selecQueryElem);
		$updateQuery = mysql_query("update document set likes='".$selectQueryElemNew."' where id='".$statusId."'");
		$update = mysql_query("UPDATE `document` SET `like` = `like`-'1'  WHERE `document`.`id`=".$statusId);
	}
	function dislikeStatus($statusId)
	{
		$updateQuery = mysql_query("update document set dislikes=concat(dislikes,',".$_SESSION['user_id']."') where id='".$statusId."'");
		$update = mysql_query("UPDATE `document` SET `dislike` = `dislike`+'1'  WHERE `document`.`id`=".$statusId);
	}
	function undislikeStatus($statusId)
	{
		$selectQuery = mysql_fetch_array(mysql_query("select dislikes from document where id='".$statusId."'"));
		$selecQueryElem = explode(",",$selectQuery['dislikes']);
		print_r($selecQueryElem);
		if(($key = array_search($_SESSION['user_id'], $selecQueryElem)) !== false) {
    		unset($selecQueryElem[$key]);
		}
		$selectQueryElemNew = implode(",",$selecQueryElem);
		$updateQuery = mysql_query("update document set dislikes='".$selectQueryElemNew."' where id='".$statusId."'");
		$update = mysql_query("UPDATE `document` SET `dislike` = `dislike`-'1'  WHERE `document`.`id`=".$statusId);
	}

	function getFriends()
	{
		$selectQuery = mysql_query("select friend_id from friends where user_id='".$_SESSION['user_id']."'");
		$i=0;
		$friends[] = "";
		while($row = mysql_fetch_array($selectQuery))
		{
			$friends[$i]['friend_id'] = $row['friend_id'];
			$friends[$i]['fullname'] = $this->getUserFullname($row['friend_id']);
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $friends;
		}	
	}
	
	function getDashboardStatus()
	{
		$statusQuery = mysql_query("select * from document where (user_id in (select friend_id from friends where user_id='".$_SESSION['user_id']."') || user_id='".$_SESSION['user_id']."') || (id in(select id from document_share where user_id in(select friend_id from friends where user_id='".$_SESSION['user_id']."') || user_id='".$_SESSION['user_id']."'))  ORDER BY `update_time` DESC");
		$i=0;
		$userStatus[] = "";
		while($row = mysql_fetch_array($statusQuery))
		{
			$userStatus[$i]['id'] = $row['id'];
			$userStatus[$i]['type'] = $row['type'];
			$userStatus[$i]['comment'] = $row['comment'];
			$userStatus[$i]['url'] = $row['url'];
			$userStatus[$i]['category']= $row['category'];
			$userStatus[$i]['privacy'] = $row['privacy'];
			$userStatus[$i]['thumbnail'] = $row['thumbnail'];
			$userStatus[$i]['place'] = $row['place'];
			$userStatus[$i]['date'] = $row['date'];
			$userStatus[$i]['update_time'] = $this->ago($row['update_time']);
			$userStatus[$i]['like'] = $row['like'];
			$userStatus[$i]['dislike'] = $row['dislike'];
			$userStatus[$i]['comments'] = $row['comments'];
			$userStatus[$i]['user_id'] = $row['user_id'];
			$userStatus[$i]['fullname'] = $this->getUserFullname($row['user_id']);
			$likesArray = explode(",",$row['likes']);
			if(in_array($_SESSION['user_id'] , $likesArray))
			{
				$userStatus[$i]['likes'] = true;
			}
			else
			{
				$userStatus[$i]['likes'] = false;
			}
			$dislikesArray = explode(",",$row['dislikes']);
			if(in_array($_SESSION['user_id'] , $dislikesArray))
			{
				$userStatus[$i]['dislikes'] = true;
			}
			else
			{
				$userStatus[$i]['dislikes'] = false;
			}
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $userStatus;
		}	
	}
	
	function getUserFullname($userId)
	{
		$selectQuery = mysql_query("select fullname from user where user_id='".$userId."'");
		$selectArray = mysql_fetch_array($selectQuery);
		return $selectArray['fullname'];
	}
	
	function shareStatus($statusId)
	{
		$timeAr = getdate();
		$selectQuery = mysql_query("select * from document where id='".$statusId."'");
		$selectArray = mysql_fetch_array($selectQuery);
		$insertQuery = mysql_query("INSERT INTO `document_share`(`document_id`, `user_id`) VALUES ('".$statusId."','".$_SESSION['user_id']."')");
		$insertQuery = mysql_query("INSERT INTO `document`(`user_id`, `type`, `comment`, `url`, `category`, `privacy`, `thumbnail`, `place`, `date`, `update_time`, `like`, `dislike`, `comments`, `likes`, `dislikes`) VALUES ('".$_SESSION['user_id']."','".$selectArray['type']."','".$selectArray['comment']."','".$selectArray['url']."','".$selectArray['category']."','".$selectArray['privacy']."','".$selectArray['thumbnail']."','".$selectArray['place']."','".$selectArray['date']."','".$timeAr[0]."',0,0,0,0,0)");
	}
	
	function likeComment($commentId)
	{
		$updateQuery = mysql_query("update comment set likes=concat(likes,',".$_SESSION['user_id']."') where id='".$commentId."'");
		$update = mysql_query("UPDATE `comment` SET `like` = `like`+'1'  WHERE `comment`.`id`=".$commentId);
	}
	function unlikeComment($commentId)
	{
		$selectQuery = mysql_fetch_array(mysql_query("select likes from comment where id='".$commentId."'"));
		$selecQueryElem = explode(",",$selectQuery['likes']);
		print_r($selecQueryElem);
		if(($key = array_search($_SESSION['user_id'], $selecQueryElem)) !== false) {
    		unset($selecQueryElem[$key]);
		}
		$selectQueryElemNew = implode(",",$selecQueryElem);
		$updateQuery = mysql_query("update comment set likes='".$selectQueryElemNew."' where id='".$commentId."'");
		$update = mysql_query("UPDATE `comment` SET `like` = `like`-'1'  WHERE `comment`.`id`=".$commentId);
	}
	function dislikeComment($commentId)
	{
		$updateQuery = mysql_query("update comment set dislikes=concat(dislikes,',".$_SESSION['user_id']."') where id='".$commentId."'");
		$update = mysql_query("UPDATE `comment` SET `dislike` = `dislike`+'1'  WHERE `comment`.`id`=".$commentId);
	}
	function undislikeComment($commentId)
	{
		$selectQuery = mysql_fetch_array(mysql_query("select dislikes from comment where id='".$commentId."'"));
		$selecQueryElem = explode(",",$selectQuery['dislikes']);
		print_r($selecQueryElem);
		if(($key = array_search($_SESSION['user_id'], $selecQueryElem)) !== false) {
    		unset($selecQueryElem[$key]);
		}
		$selectQueryElemNew = implode(",",$selecQueryElem);
		$updateQuery = mysql_query("update comment set dislikes='".$selectQueryElemNew."' where id='".$commentId."'");
		$update = mysql_query("UPDATE `comment` SET `dislike` = `dislike`-'1'  WHERE `comment`.`id`=".$commentId);
	}

	function likeReply($replyId)
	{
		$updateQuery = mysql_query("update comment set likes=concat(likes,',".$_SESSION['user_id']."') where id='".$replyId."'");
		$update = mysql_query("UPDATE `comment` SET `like` = `like`+'1'  WHERE `comment`.`id`=".$replyId);
	}
	function unlikeReply($replyId)
	{
		$selectQuery = mysql_fetch_array(mysql_query("select likes from comment where id='".$replyId."'"));
		$selecQueryElem = explode(",",$selectQuery['likes']);
		if(($key = array_search($_SESSION['user_id'], $selecQueryElem)) !== false) {
    		unset($selecQueryElem[$key]);
		}
		$selectQueryElemNew = implode(",",$selecQueryElem);
		$updateQuery = mysql_query("update comment set likes='".$selectQueryElemNew."' where id='".$replyId."'");
		$update = mysql_query("UPDATE `comment` SET `like` = `like`-'1'  WHERE `comment`.`id`=".$replyId);
	}
	function dislikeReply($replyId)
	{
		$updateQuery = mysql_query("update comment set dislikes=concat(dislikes,',".$_SESSION['user_id']."') where id='".$replyId."'");
		$update = mysql_query("UPDATE `comment` SET `dislike` = `dislike`+'1'  WHERE `comment`.`id`=".$replyId);
	}
	function undislikeReply($replyId)
	{
		$selectQuery = mysql_fetch_array(mysql_query("select dislikes from comment where id='".$replyId."'"));
		$selecQueryElem = explode(",",$selectQuery['dislikes']);
		if(($key = array_search($_SESSION['user_id'], $selecQueryElem)) !== false) {
    		unset($selecQueryElem[$key]);
		}
		$selectQueryElemNew = implode(",",$selecQueryElem);
		$updateQuery = mysql_query("update comment set dislikes='".$selectQueryElemNew."' where id='".$replyId."'");
		$update = mysql_query("UPDATE `comment` SET `dislike` = `dislike`-'1'  WHERE `comment`.`id`=".$replyId);
	}
	
	function getUserDetail($userid)
	{
		$selectQuery = mysql_query("select * from user where user_id = '".$userid."'");
		$i=0;
		$userDetail[] = "";
		while($row = mysql_fetch_array($selectQuery))
		{
			$userDetail[$i]['fullname'] = $row['fullname'];
			$userDetail[$i]['gender'] = $row['gender'];
			$userDetail[$i]['dob'] = $row['dob'];
			$userDetail[$i]['relationship'] = $row['relationship'];
			$userDetail[$i]['city']= $row['city'];
			$userDetail[$i]['citizenship'] = $row['citizenship'];
			$userDetail[$i]['about'] = $row['about'];
			$userDetail[$i]['workfield'] = $row['workfield'];
			$userDetail[$i]['interest'] = $row['interest'];
			$userDetail[$i]['phone'] = $this->ago($row['phone']);
			$userDetail[$i]['mobile'] = $row['mobile'];
			$userDetail[$i]['email'] = $row['email'];
			$userDetail[$i]['fax'] = $row['fax'];
			$userDetail[$i]['school'] = $row['school'];
			$userDetail[$i]['college'] = $row['college'];
			$userDetail[$i]['pgcollege'] = $row['pgcollege'];
			$userDetail[$i]['other'] = $row['other'];
			$userDetail[$i]['profilepic'] = $row['profilepic'];
			
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $userDetail;
		}
	}
	
	
	function wallDetail($userid)
	{
		echo "hi";
	

	}
	

	function getFriendList($userid)
	{
		$i= 0;
		$selectQuery = mysql_query("select *,user.user_id as Id from friends,user where (friends.user_id = '".$userid."'  && friends.friend_id = user.user_id ) || (friends.friend_id='".$userid."' && friends.user_id = user.user_id)");
		while($row = mysql_fetch_array($selectQuery))
		{
			$friendDetail[$i]['user_id'] = $row['user_id'];
			$friendDetail[$i]['friend_id'] = $row['friend_id'];
			$friendDetail[$i]['fullname'] = $row['fullname'];
			$friendDetail[$i]['profilepic'] = $row['profilepic'];
			$friendDetail[$i]['Id'] = $row['Id'];
			$friendDetail[$i]['gender'] = $row['gender'];
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $friendDetail;
		}
	}

	function getFriendship($userId)
	{
		$selectQuery = mysql_query("SELECT * FROM `friends` where (user_id='".$_SESSION['user_id']."' && friend_id='".$userId."') || (user_id='".$userId."' && friend_id='".$_SESSION['user_id']."')");
		if(mysql_num_rows($selectQuery)>0)
		{
			return 1;
		}
		else
		{
			$selectQuery = mysql_query("SELECT * FROM `friend_request` where (user_id='".$_SESSION['user_id']."' && friend_id='".$userId."') || (user_id='".$userId."' && friend_id='".$_SESSION['user_id']."')");
			if(mysql_num_rows($selectQuery)>0)
			{
				return 2;
			}
			else
			{
				return 0;
			}
		}
	}

	function sendFriendRequest($userId)
	{
		$replyQuery = mysql_query("INSERT INTO `friend_request`(`user_id`, `friend_id`, `gender`) VALUES ('".$_SESSION['user_id']."','".$userId."','female')");
		return;
	}

	function getFemaleFriendReq()
	{
		$i= 0;
		$selectQuery = mysql_query("select *,user.user_id as Id from friends,user where (friends.user_id = '".$_SESSION['user_id']."'  && friends.friend_id = user.user_id ) || (friends.friend_id='".$_SESSION['user_id']."' && friends.user_id = user.user_id) && gender='female'");
		while($row = mysql_fetch_array($selectQuery))
		{
			$friendDetail[$i]['user_id'] = $row['user_id'];
			$friendDetail[$i]['friend_id'] = $row['friend_id'];
			$friendDetail[$i]['fullname'] = $row['fullname'];
			$friendDetail[$i]['profilepic'] = $row['profilepic'];
			$friendDetail[$i]['Id'] = $row['Id'];
			$friendDetail[$i]['gender'] = $row['gender'];
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $friendDetail;
		}

	}

	function getMaleFriendReq()
	{
	}
	
	//////////////// Anuja /////////////
	public function editprofile($dob,$gender)
	{
		if(empty($gender)) 
		{
			$error =  '* Please Select gender ';
    	} 
    	elseif(empty($dob))
		{
			$error = '* Please Select dob ';
    	}
		/*elseif (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) 
		{
            $error = '* Your Email Address is invalid  ';
        }
        elseif(empty($password) || $password == "Password") 
		{
        	$error = '* Please Enter Your Password ';
    	}*/
		elseif(empty($error)) //send to Database if there's no error '
    	{ // If everything's OK...
        	// Make sure the email address is available:
        	/*$query_verify_email = "SELECT * FROM user  WHERE email ='$email'";
        	$result_verify_email = mysql_query($query_verify_email);
        	if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false)
            	echo ' Database Error Occured ';
        }*/
        //if(mysql_num_rows($error) == 0) 
		//{ 		
			$gender = mysql_real_escape_string($gender);
			$dob = mysql_real_escape_string($dob);
			//$password = mysql_real_escape_string($password);

			// IF no previous user is using this email .
            // Create a unique  activation code:
            //$activation = md5(uniqid(rand(), true));
            $query_update_user = "UPDATE `user` set `gender`='".$gender."',`dob` ='".$dob."'";
            $result_update_user = mysql_query($query_update_user);
            if (!$result_update_user) 
			{
                echo 'Query Failed ';
            }
            if (mysql_affected_rows() == 1)
			{
                //$message = " To activate your account, please click on this link:\n\n";
                //$message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
				//$message = "Dear Bhavika Thakkar\nThank you for registering with ve.com. Your journey to success begins now!\n\nPlease find below your account details:\nUsername: ".$email."\nPassword: ".$password." \n DO NOT REPLY TO THIS MAIL \n You received this email as a member of VaultEmpire.com ";
                //mail($email, 'Registration Confirmation', $message, 'From: bhavikat6@gmail.com');
				//$this->login($email,$password);
                // Finish the page:
			}
			else 
			{ // If it did not run OK.
                $error = '* Oops something went wrong.';
            }
		/*} 
		else 
		{	 // The email address is not available.
           	$error = '* Email Id already registered';
		}*/
		
		}
		echo $error;
	}
	
	
	
	public function msgsubmit($message)
	{

		if(empty($message) || $message == "message") 
		{
			$error =  '* Please Enter something ';
    	} 
    	
		
		elseif(empty($error)) //send to Database if there's no error '
    	{  		
			
			
		//echo "hiiiii";	
			//$messg = mysql_real_escape_string($messg);
			//$from_uid = mysql_real_escape_string($_SESSION['user_id']);
			//$user_id= mysql_real_escape_string($_SESSION['user_id']);
	
            $query_add_msg = "INSERT INTO `msgs`(`message`, `user_id`, `from_user_id`) VALUES ('".$message."','','')";
            $result_add_msg = mysql_query($query_add_msg);
            if (!$result_add_msg) 
			{
                echo 'Query Failed ';
            }
			else 
			{	
				echo "message sent";
			}
		
		}
		echo $error;
	}
	
function vaultImageFileUpload($comments,$title,$album,$privacy,$category,$filename,$new_suggest)
{
if($privacy == 'public')
{
$pr = 2;
}
elseif($privacy == "private")
{
$pr = 0;
}
elseif($privacy == 'friends')
{
$pr = 1;
}
//$comments = urldecode($comments);
//$title = urldecode($title);
if(!is_dir("vault/".$_SESSION['user_id']))
 mkdir("vault/".$_SESSION['user_id'],0777);
if(!is_dir("vault/".$_SESSION['user_id']."/image"))
 mkdir("vault/".$_SESSION['user_id']."/image",0777);
if(!is_dir("vault/".$_SESSION['user_id']."/image/".$album))
 mkdir("vault/".$_SESSION['user_id']."/image/".$album,0777);
//$file_id='imageFile';
/*$status='';*/
$folderId = '1';
$inserId = 0;
$filename=$_FILES['imageFile']['name'];
$tmpfile=$_FILES['imageFile']['tmp_name'];
$timeAr = getdate();
$album_insert=mysql_query("INSERT INTO `album`(`album`,`desc`,`user_id`) VALUES ('".$album."','".$comments."','".$_SESSION['user_id']."')");
$album_id=mysql_insert_id();
for ($i = 0; $i < count($_FILES['imageFile']['name']); $i++) {
$ext = substr(strrchr($_FILES['imageFile']['name'][$i], "."), 1);
// generate a random new file name to avoid name conflict
if($ext == "3dm" || $ext == "3ds" || $ext == "max" || $ext == "obj" || $ext== "bmp" || $ext == "dds" || $ext == "dng" || $ext == "gif" || $ext == "jpg" || $ext == "png" || $ext == "psd" || $ext == "pspimage" || $ext == "tga"  || $ext == "thm" || $ext == "svg" || $ext == "tif" || $ext == "yuv" || $ext == "ai" || $ext == "eps" || $ext == "ps" )
{
$fPath = $_FILES['imageFile']['name'][$i];
$result = move_uploaded_file($_FILES['imageFile']['tmp_name'][$i], "vault/".$_SESSION['user_id']."/image/".$album."/" . $fPath);
}
else { echo "wrong format of file"; }
if (strlen($ext) > 0){;

if($category == '0')
{
$cat_insert=mysql_query("INSERT INTO `category`(`name`) VALUES ('".$new_suggest."')");
}


function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

$ipadd=getRealIpAddr();


$query_check_credentials = "INSERT INTO `vaultdocument`(`album_id`, `type`, `url`, `category_id`, `privacy`,`thumbnail`, `place`, `date`,`update_time`,`like`,`dislike`,`comments`,`likes`,`dislikes`,`user_id`,`user_ip`) VALUES ('".$album_id."','image','".$fPath."','".$category."','".$pr."','','".$filename."','','".$timeAr[0]."','','','','','','".$_SESSION['user_id']."','".$ipadd."')";
$result_check_credentials = mysql_query($query_check_credentials);
}
}
}			
		

function videoUpload($album,$title,$comments,$privacy,$category,$new_suggest)
{
//$comments = urldecode($comments);
//$title = urldecode($title);
if(!is_dir("vault/".$_SESSION['user_id']))
  mkdir("vault/".$_SESSION['user_id'],0777);
if(!is_dir("vault/".$_SESSION['user_id']."/video"))
  mkdir("vault/".$_SESSION['user_id']."/video",0777);
if(!is_dir("vault/".$_SESSION['user_id']."/video/".$album))
 mkdir("vault/".$_SESSION['user_id']."/video/".$album,0777);
$file_id='videofile';
$status='';
$folderId = '1';
$inserId = 0;
$filename=$_FILES['videofile']['name'];
$tmpfile=$_FILES['videofile']['tmp_name'];
$timeAr = getdate();

$ext = end(explode(".", $_FILES['videofile']['name']));
if($ext == "flv" || $ext == "mp4" || $ext == "m3u8" || $ext == "ts" || $ext== "3gp" || $ext == "mov" || $ext == "avi" || $ext == "wmv")
{
$fPath = $_FILES['videofile']['name'];
//$result=move_uploaded_file($tmpfile, "vault/".$_SESSION['user_id']."/music/".$filename);
$result = move_uploaded_file($_FILES['videofile']['tmp_name'], "vault/".$_SESSION['user_id']."/video/".$album."/" . $fPath);

$album_insert=mysql_query("INSERT INTO `album`(`album`,`desc`,`user_id`) VALUES ('".$album."','".$comments."','".$_SESSION['user_id']."')");
$album_id=mysql_insert_id();
if($title == "")
{
$title = $filename;
}
if($privacy == 'public')
{
$pr = 2;
}
elseif($privacy == "private")
{
$pr = 0;
}
elseif($privacy == 'friends')
{
$pr = 1;
}

if($category == '0')
{
$cat_insert=mysql_query("INSERT INTO `category`(`name`) VALUES ('".$new_suggest."')");
}

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

$ipadd=getRealIpAddr();

$query_check_credentials = "INSERT INTO `vaultdocument`(`album_id`, `type`, `url`, `category_id`, `privacy`, `thumbnail`, `place`, `date`,`update_time`,`like`,`dislike`,`comments`,`likes`,`dislikes`,`user_id`,`user_ip`) VALUES ('".$album_id."','video','".$filename."','".$category."','".$pr."','','".$title."','".$timeAr[0]."','','','','','','','".$_SESSION['user_id']."','".$ipadd."')";
$result_check_credentials = mysql_query($query_check_credentials);
//$album=mysql_query("INSERT INTO `album`(`album`,`user_id`) VALUES ('".$title."','".$_SESSION['user_id']."')");
//$error = "<span style='color:green;margin-top:30px;'>File added successfully</span>";
}
else
{
$error = "<span style='color:red'>Invalid file type</span>";
}
//return (mysql_real_escape_string($error));
}

function musicUpload($comments,$title,$album,$privacy,$category,$new_suggest)
{
$comments = urldecode($comments);
$title = urldecode($title);
if(!is_dir("vault/".$_SESSION['user_id']))
  mkdir("vault/".$_SESSION['user_id'],0777);
if(!is_dir("vault/".$_SESSION['user_id']."/music"))
  mkdir("vault/".$_SESSION['user_id']."/music",0777);
if(!is_dir("vault/".$_SESSION['user_id']."/music/".$album))
 mkdir("vault/".$_SESSION['user_id']."/music/".$album,0777);
 
$file_id='file';
$status='';
$folderId = '1';
$inserId = 0;
$filename=$_FILES['file']['name'];
$tmpfile=$_FILES['file']['tmp_name'];
$timeAr = getdate();

$ext = end(explode(".", $_FILES['file']['name']));
if($ext == "au" || $ext == "snd" || $ext == "mid" || $ext == "rmi" || $ext== "mp3" || $ext == "aif" || $ext == "aifc" || $ext == "aiff" || $ext== "m3u" || $ext== "ra" || $ext== "ram" || $ext== "wav")
{
$fPath = $_FILES['file']['name'];
//$result=move_uploaded_file($tmpfile, "vault/".$_SESSION['user_id']."/music/".$filename);
$result = move_uploaded_file($_FILES['file']['tmp_name'], "vault/".$_SESSION['user_id']."/music/".$album."/" . $fPath);
$album_insert=mysql_query("INSERT INTO `album`(`album`,`desc`,`user_id`) VALUES ('".$album."','".$comments."','".$_SESSION['user_id']."')");
$album_id=mysql_insert_id();
if($title == "")
{
$title = $filename;
}
if($privacy == 'public')
{
$pr = 2;
}
elseif($privacy == "private")
{
$pr = 0;
}
elseif($privacy == 'friends')
{
$pr = 1;
}

if($category == '0')
{
$cat_insert=mysql_query("INSERT INTO `category`(`name`) VALUES ('".$new_suggest."')");
}

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

$ipadd=getRealIpAddr();

$query_check_credentials = "INSERT INTO `vaultdocument`(`album_id`, `type`, `url`, `category_id`, `privacy`, `thumbnail`, `place`, `date`,`update_time`,`like`,`dislike`,`comments`,`likes`,`dislikes`,`user_id`,`user_ip`) VALUES ('".$album_id."','music','".$filename."','".$category."','".$pr."','','".$title."','".$timeAr[0]."','','','','','','','".$_SESSION['user_id']."','".$ipadd."')";
$result_check_credentials = mysql_query($query_check_credentials);
//$album=mysql_query("INSERT INTO `album`(`album`,`user_id`) VALUES ('".$title."','".$_SESSION['user_id']."')");
//$error = "<span style='color:green;margin-top:30px;'>File added successfully</span>";
}
else
{
$error = "<span style='color:red'>Invalid file type</span>";
}
//return (mysql_real_escape_string($error));
}
	
	
function docUpload($album,$title,$comments,$privacy,$category,$new_suggest)
{
$comments = urldecode($comments);
$title = urldecode($title);
if(!is_dir("vault/".$_SESSION['user_id']))
  mkdir("vault/".$_SESSION['user_id'],0777);
if(!is_dir("vault/".$_SESSION['user_id']."/documents"))
  mkdir("vault/".$_SESSION['user_id']."/documents",0777);
if(!is_dir("vault/".$_SESSION['user_id']."/documents/".$album))
 mkdir("vault/".$_SESSION['user_id']."/documents/".$album,0777);
$file_id='docfile';
$status='';
$folderId = '1';
$inserId = 0;
$filename=$_FILES['docfile']['name'];
$tmpfile=$_FILES['docfile']['tmp_name'];
$timeAr = getdate();

$ext = end(explode(".", $_FILES['docfile']['name']));
if($ext == "doc" || $ext == "docx" || $ext == "txt" || $ext == "csv" || $ext== "log" || $ext == "ppt" || $ext == "xml" || $ext == "pdf" || $ext== "xls" || $ext== "sql" || $ext== "mdb" || $ext== "db" || $ext== "exe" || $ext== "html" || $ext== "zip" || $ext== "tar.gz" || $ext== "php" || $ext== "rss" || $ext== "js" || $ext== "jsp" || $ext== "htm" || $ext== "ini" || $ext== "ico" || $ext== "dll" || $ext== "c" || $ext== "cpp" || $ext== "fla")
{
$fPath = $_FILES['docfile']['name'];
//$result=move_uploaded_file($tmpfile, "vault/".$_SESSION['user_id']."/music/".$filename);
$result = move_uploaded_file($_FILES['docfile']['tmp_name'], "vault/".$_SESSION['user_id']."/documents/".$album."/" . $fPath);

$album_insert=mysql_query("INSERT INTO `album`(`album`,`desc`,`user_id`) VALUES ('".$album."','".$comments."','".$_SESSION['user_id']."')");
$album_id=mysql_insert_id();
if($title == "")
{
$title = $filename;
}
if($privacy == 'public')
{
$pr = 2;
}
elseif($privacy == "private")
{
$pr = 0;
}
elseif($privacy == 'friends')
{
$pr = 1;
}

if($category == '0')
{
	$cat_insert=mysql_query("INSERT INTO `category`(`name`) VALUES ('".$new_suggest."')");
}

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

$ipadd=getRealIpAddr();

$query_check_credentials = "INSERT INTO `vaultdocument`(`album_id`, `type`, `url`, `category_id`, `privacy`, `thumbnail`, `place`, `date`,`update_time`,`like`,`dislike`,`comments`,`likes`,`dislikes`,`user_id`,`user_ip`) VALUES ('".$album_id."','documents','".$filename."','".$category."','".$pr."','','".$title."','".$timeAr[0]."','','','','','','','".$_SESSION['user_id']."','".$ipadd."')";
$result_check_credentials = mysql_query($query_check_credentials);
//$album=mysql_query("INSERT INTO `album`(`album`,`user_id`) VALUES ('".$title."','".$_SESSION['user_id']."')");
//$error = "<span style='color:green;margin-top:30px;'>File added successfully</span>";
}
else
{
$error = "<span style='color:red'>Invalid file type</span>";
}
//return (mysql_real_escape_string($error));
}	
	
	function getmusic()
	{
		if(isset($_POST['cid']) && $_POST['cid']!='')
			{
		
		$c=$_POST['cid'];
		$selectQuery = mysql_query("select * from vaultdocument where user_id = '".$_SESSION['user_id']."' AND type='music' AND privacy='2' AND category_id='".$c."' order by likes desc");
			}
			else
			{
			
		$selectQuery = mysql_query("select * from vaultdocument where user_id = '".$_SESSION['user_id']."' AND type='music' AND privacy='2' order by likes desc");
			}
		//$c=count($selectQuery);
		$i=0;
		$musicDetail[] = "";
		while($row = mysql_fetch_array($selectQuery))
		{
			$musicDetail[$i]['url'] = $row['url'];
			$musicDetail[$i]['likes'] = $row['likes'];
			$musicDetail[$i]['dislikes'] = $row['dislikes'];
			
			$i++;
		}
			return $musicDetail;
	}
	
	
	function getimg()
	{
		if(isset($_POST['iid']) && $_POST['iid']!='')
			{
		
		$im=$_POST['iid'];
		$selectQuery = mysql_query("select * from vaultdocument as v,album as a where v.album_id=a.album_id and v.user_id = '".$_SESSION['user_id']."' AND v.type='image' AND v.privacy='2' AND category_id='".$im."' order by v.likes desc ");
			}
			else
			{
		$selectQuery = mysql_query("select * from vaultdocument as v,album as a where v.album_id=a.album_id and v.user_id = '".$_SESSION['user_id']."' AND v.type='image' AND v.privacy='2' order by v.likes desc ");
			}
		$c=count($selectQuery);
		$i=0;
		$imgDetail[] = "";
		while($row = mysql_fetch_array($selectQuery))
		{
			$imgDetail[$i]['url'] = $row['url'];
			$imgDetail[$i]['likes'] = $row['likes'];
			$imgDetail[$i]['dislikes'] = $row['dislikes'];
			$imgDetail[$i]['album'] = $row['album'];
			$i++;
		}
			return $imgDetail;
	}
	
	
		function getvideo()
		{
			if(isset($_POST['vid']) && $_POST['vid']!='')
			{
			$vid=$_POST['vid'];
			$selectQuery = mysql_query("select * from vaultdocument as v,album as a where v.album_id=a.album_id and v.user_id = '".$_SESSION['user_id']."' AND v.type='video' AND v.privacy='2' AND category_id='".$vid."' order by v.likes desc ");
			}
			else
			{
			$selectQuery = mysql_query("select * from vaultdocument as v,album as a where v.album_id=a.album_id and v.user_id = '".$_SESSION['user_id']."' AND v.type='video' AND v.privacy='2' order by v.likes desc ");
			}
			$c=count($selectQuery);
			$i=0;
			$videoDetail[] = "";
			while($row = mysql_fetch_array($selectQuery))
			{
				$videoDetail[$i]['url'] = $row['url'];
				$videoDetail[$i]['likes'] = $row['likes'];
				$videoDetail[$i]['dislikes'] = $row['dislikes'];
				$videoDetail[$i]['album'] = $row['album'];
				$i++;
			}
				return $videoDetail;
		}
		
		
		function getdoc()
		{
			if(isset($_POST['did']) && $_POST['did']!='')
			{
			$vid=$_POST['did'];
			$selectQuery = mysql_query("select * from vaultdocument as v,album as a where v.album_id=a.album_id and v.user_id = '".$_SESSION['user_id']."' AND v.type='documents' AND v.privacy='2' AND category_id='".$vid."' order by v.likes desc ");
			}
			else
			{
			$selectQuery = mysql_query("select * from vaultdocument as v,album as a where v.album_id=a.album_id and v.user_id = '".$_SESSION['user_id']."' AND v.type='documents' AND v.privacy='2' order by v.likes desc ");
			}
			$c=count($selectQuery);
			$i=0;
			$docDetail[] = "";
			while($row = mysql_fetch_array($selectQuery))
			{
				$docDetail[$i]['url'] = $row['url'];
				$docDetail[$i]['likes'] = $row['likes'];
				$docDetail[$i]['dislikes'] = $row['dislikes'];
				$docDetail[$i]['album'] = $row['album'];
				$i++;
			}
				if($i == 0)
			{
				echo "no records found";
			}
			else
			{
				//echo "no records";
				return $docDetail;
			}
		}
	
	
	function suggestCat($q)
	{
		$sql = "select DISTINCT(category) from vaultdocument where category LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
	$cname = $rs['category'];
	echo "$cname\n";
	}
	}
	
	function albumName($album_name)
	{
		$sql = "select * from album as a, vaultdocument as v where a.album_id=v.album_id and v.user_id='".$_SESSION['user_id']."' and a.album='".$album_name."'";
		$rsd = mysql_query($sql);
		if(mysql_num_rows($rsd)>0)
		{
			echo "<span style='color:red;font-size:12px;'>Album Name already exists</span>";
		}
		
		return $sql;
	}
	
	
	function getcat()
		{
			$selectQuery = mysql_query("select * from category");
			
			$c=count($selectQuery);
			
			$cat[] = "";
			$i='0';
			while($row = mysql_fetch_array($selectQuery))
			{
				$cat[$i]['id'] = $row['id'];
				$cat[$i]['name'] = $row['name'];
				$i++;
			}
				if($i == 0)
			{
				return 0;
			}
			else
			{
				return $cat;
			}
		}
		
		
		function getFriendName($userid)
		{
		$selectQuery = mysql_query("select * from user where user_id = '".$userid."'");
		$i=0;
		$friendName[] = "";
		while($row = mysql_fetch_array($selectQuery))
		{
			$friendName[$i]['fullname'] = $row['fullname'];
			$friendName[$i]['gender'] = $row['gender'];
			$friendName[$i]['dob'] = $row['dob'];
			$friendName[$i]['relationship'] = $row['relationship'];
			$friendName[$i]['city']= $row['city'];
			$friendName[$i]['citizenship'] = $row['citizenship'];
			$friendName[$i]['about'] = $row['about'];
			$friendName[$i]['workfield'] = $row['workfield'];
			$friendName[$i]['interest'] = $row['interest'];
			$friendName[$i]['phone'] = $this->ago($row['phone']);
			$friendName[$i]['mobile'] = $row['mobile'];
			$friendName[$i]['email'] = $row['email'];
			$friendName[$i]['fax'] = $row['fax'];
			$friendName[$i]['school'] = $row['school'];
			$friendName[$i]['college'] = $row['college'];
			$friendName[$i]['pgcollege'] = $row['pgcollege'];
			$friendName[$i]['other'] = $row['other'];
			$friendName[$i]['profilepic'] = $row['profilepic'];
			
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $friendName;
		}
	}
	
	function addMsg($frndid,$msg)
	{
		//$q=mysql_query("select * from msgs where user_d='".$frndid."' and from_user_id='".$_SESSION['user_id']."'");
		
		
			$msg_insert=mysql_query("INSERT INTO `msgs`(`message`,`user_id`,`from_user_id`,`type`,`mid`) VALUES ('".$msg."','".$frndid."','".$_SESSION['user_id']."','main','0')");
		
		
		return $msg_insert;
	}	

	function getMessages()
		{
		$selectQuery = mysql_query("select * from msgs as m, user as u where u.user_id=m.from_user_id and m.user_id='".$_SESSION['user_id']."'");
		$i=0;
		$messages[] = "";
		while($row = mysql_fetch_array($selectQuery))
		{
			$messages[$i]['message'] = $row['message'];
			$messages[$i]['from_user_id'] = $row['from_user_id'];
			$messages[$i]['fullname'] = $row['fullname'];
			$messages[$i]['msg_id'] = $row['msg_id'];
			
			$i++;
		}
		if($i == 0)
		{
			return 0;
		}
		else
		{
			return $messages;
		}
	}
	
	
	function sendReply($to,$reply,$mid)
	{
		$msg_insert=mysql_query("INSERT INTO `msgs`(`message`,`user_id`,`from_user_id`,`type`,`mid`) VALUES ('".$reply."','".$to."','".$_SESSION['user_id']."','reply','".$mid."')");
		//return $msg_insert;
		header('location:../index.php?action=messages');
	}
	
	
	function getReply($m)
		{
		$selectQuery = mysql_query("select * from msgs where type='reply' and mid='".$m."'");
		$i=0;
		$reply[] = "";
		$ct=count($selectQuery);
		while($row = mysql_fetch_array($selectQuery))
		{
			$reply[$i]['message'] = $row['message'];
			$reply[$i]['from_user_id'] = $row['from_user_id'];
			//$reply[$i]['fullname'] = $row['fullname'];
			$reply[$i]['msg_id'] = $row['msg_id'];
			
			$i++;
		}
		if($i < 0)
		{
			return 0;
		}
		else
		{
			return $reply;
		}
	}
	
	
	function getImageAlbumDetails() {
       $statusQuery = mysql_query("
                                    SELECT *
                                    FROM album AS a, vaultdocument AS v
                                    WHERE v.album_id = a.album_id
                                    AND v.type = 'image'
                                    AND a.user_id = '".$_SESSION['user_id']."'
                                    GROUP BY `a`.`album`
                                    ORDER BY `v`.`id` DESC
                                ");
       $i=0;
       $albumDetail[] = "";
       while($row = mysql_fetch_array($statusQuery))
       {                   
           $albumDetail[$i]['user_id'] = $row['user_id'];
           $albumDetail[$i]['album_id'] = $row['album_id'];
           $albumDetail[$i]['album'] = $row['album'];
           $albumDetail[$i]['url'] = $row['url'];
           $albumDetail[$i]['desc'] = $row['desc'];                                       
           $i++;
       }
       if($i == 0)
       {
            return 0;
       }
       else
       {
            return $albumDetail;
       }       
    }





	
}
?>